package org.apollo.sqlite.sql.where.builder;

import org.apollo.sqlite.core.SqliteContext;
import org.apollo.sqlite.sql.Builder;

public class Comp extends Builder {
	
	public Comp(StringBuilder sqlBuilder) {
		super(sqlBuilder);
	}

	private static Comp comp(String op, String arg1, String arg2) {
		return new Comp(new StringBuilder().append(arg1).append(" ").append(op).append(" ").append(arg2));
	}

	public static Comp equal(String colum1, String colum2) {
		return comp("=", SqliteContext.getColumn(colum1), SqliteContext.getSqlValue(colum2));
	}

	public static Comp equal(String colum1, Object val) {
		return comp("=", SqliteContext.getColumn(colum1), SqliteContext.getSqlValue(val));
	}

	public static Comp notEqual(String colum1, String colum2) {
		return comp("<>", SqliteContext.getColumn(colum1), SqliteContext.getColumn(colum2));
	}

	public static Comp notEqual(String colum1, Object val) {
		return comp("<>", SqliteContext.getColumn(colum1), SqliteContext.getSqlValue(val));
	}

	public static Comp lt(String colum1, String colum2) {
		return comp("<", SqliteContext.getColumn(colum1), SqliteContext.getColumn(colum2));
	}

	public static Comp lt(String colum1, Object val) {
		return comp("<", SqliteContext.getColumn(colum1), SqliteContext.getSqlValue(val));
	}

	public static Comp gt(String colum1, String colum2) {
		return comp(">", SqliteContext.getColumn(colum1), SqliteContext.getColumn(colum2));
	}

	public static Comp gt(String colum1, Object val) {
		return comp(">", SqliteContext.getColumn(colum1), SqliteContext.getSqlValue(val));
	}

	public static Comp lte(String colum1, String colum2) {
		return comp("<=", SqliteContext.getColumn(colum1), SqliteContext.getColumn(colum2));
	}

	public static Comp lte(String colum1, Object val) {
		return comp("<=", SqliteContext.getColumn(colum1), SqliteContext.getSqlValue(val));
	}

	public static Comp gte(String colum1, String colum2) {
		return comp(">=", SqliteContext.getColumn(colum1), SqliteContext.getColumn(colum2));
	}

	public static Comp gte(String colum1, Object val) {
		return comp(">=", SqliteContext.getColumn(colum1), SqliteContext.getSqlValue(val));
	}

	public static Comp between(String colum, Object val1, Object val2) {
		return comp("BETWEEN", SqliteContext.getColumn(colum), SqliteContext.getSqlValue(val1) + " AND " + SqliteContext.getSqlValue(val2));
	}

	public static Comp in(String colum, Object... ins) {
		StringBuilder sbIns = new StringBuilder();
		sbIns.append("(");
		for (Object val : ins) {
			sbIns.append(SqliteContext.getSqlValue(val)).append(",");
		}
		sbIns.deleteCharAt(sbIns.length() - 1);
		sbIns.append(")");
		return comp("IN", SqliteContext.getColumn(colum), sbIns.toString());
	}

	public static Comp like(String colum, String like) {
		return comp("LIKE", SqliteContext.getColumn(colum), SqliteContext.getSqlValue(like));
	}
}
